"""定义接口"""

import app
import requests

class loginAPI():

    def __init__(self):
        self.getImgCode_url = app.BASE_URL +'/common/public/verifycode1/'
        self.getSmsCode_url = app.BASE_URL +'/member/public/sendSms'
        self.register_url =  app.BASE_URL + '/member/public/reg'
        self.login_url = app.BASE_URL + '/member/public/login'
    #定义获取图片验证码接口
    def getImgCode(self,session,r):
       url = self.getImgCode_url + r
       response = session.get(url)
       return response

    #定义获取短信验证码接口
    def getSmsCode(self,session,phone,imgVerifyCode):
        #准备参数
        data = {'phone':phone,'imgVerifyCode':imgVerifyCode,'type':'reg'}
        #发送请求
        response = session.post(self.getSmsCode_url,data=data)
        #返回响应
        return response

    #定义注册的接口
    def register(self,session,phone,pwd,imgverifycode='8888',phone_code='666666',dy_server='on',invite_phone=''):
        #准备参数
        data = {'phone':phone,
                'password':pwd,
                'verifycode':imgverifycode,
                'phone_code':phone_code,
                'dy_server':dy_server,
                'invite_phone':invite_phone}
        #发送请求
        response = session.post(self.register_url,data=data)
        #返回响应
        return response
    def login(self,session,phone='17563358600',pwd='628494'):
        #准备参数
        data = {'keywords':phone,'password':pwd}
        #发送请求
        response = session.post(self.login_url,data=data)
        #返回响应
        return response
